﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE80;

namespace SD007
{
    public class SolutionBuilder
    {
        public DTE2 _applicationObject;

        public long lastCompiledIndex = 0;
        public static string lastCompiledProj = "";

        public string PATH="C:\\bin\\Debug";
        public string CONTAINING_PATH = "C:\\bin\\";

        public void DoWork()
        {
            while (true)
            {
                try
                {
                    if(lastCompiledIndex == 0)
                        System.IO.Directory.Delete(CONTAINING_PATH, true);

                    string val = _applicationObject.ActiveDocument.ProjectItem.ContainingProject.ConfigurationManager.
                        ActiveConfiguration.Properties.Item("OutputPath").Value.ToString();
                    string backupVal = val;
                    lastCompiledProj = PATH + (lastCompiledIndex++);
                    
                    _applicationObject.ActiveDocument.ProjectItem.ContainingProject.ConfigurationManager.
                        ActiveConfiguration.Properties.Item("OutputPath").Value = lastCompiledProj;
                    _applicationObject.Solution.SolutionBuild.Build();

                    System.Threading.Thread.Sleep(5000);

                    _applicationObject.ActiveDocument.ProjectItem.ContainingProject.ConfigurationManager.
                        ActiveConfiguration.Properties.Item("OutputPath").Value = backupVal;
                }
                catch (Exception)
                {
                    
                }
            }
        }
    }
}
